package org.x.usermod.mapper;

import cn.dev33.satoken.stp.StpUtil;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryWrapper;
import org.x.usermod.dto.CodeDTO;
import org.x.usermod.entity.SysAclEntity;
import org.x.usermod.entity.SysRoleAcl;
import org.x.usermod.entity.SysRoleUser;

import java.util.List;

public interface CodeMapper extends BaseMapper<CodeDTO> {

    default List<CodeDTO> getCode() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.select(SysAclEntity::getCode, SysAclEntity::getName, SysAclEntity::getId)
                .from(SysRoleUser.class)
                .leftJoin(SysRoleAcl.class)
                .on(SysRoleUser::getRoleId, SysRoleAcl::getRoleId)
                .leftJoin(SysAclEntity.class).on(SysRoleAcl::getAclId, SysAclEntity::getId)
                .where("user_id = " + StpUtil.getLoginIdAsLong());

        List<CodeDTO> codeDTOs = this.selectListByQuery(queryWrapper);
        return codeDTOs;
    }
}